import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class ServerSockerTest {

   public static void main(String[] args){
        ServerSocket serverSocket = null;
        Socket socket = null;
       List<String> strList = new ArrayList<String>();

       try {
           serverSocket = new ServerSocket(3000);
           while(true){
               System.out.println("等待客户端的连接请求...");
               socket = serverSocket.accept();
               System.out.println(socket.getInetAddress().toString() + ":" + socket.getPort() + "客户端连接成功...");
               new ServerSocketThread(socket,strList).start();
           }
       }
       catch (Exception e){
           e.printStackTrace();
       }finally {
           System.out.println("---------------------------------Server端停止执行-----------------------------------------");
           try {
               if(null != socket){
                   socket.close();
               }
               if(null != serverSocket){
                   serverSocket.close();
               }
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
   }

}
